package com.ymatou.iapi.productmanager.testcase;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.productmanager.parameter.GetNewProductDescriptionInfoBean;
import com.ymatou.iapi.productmanager.parameter.ModifyProductDescriptionBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.productDesc.ProductDescriptionInfoDto;
import com.ymatou.iapi.productmanager.parameter.productDesc.ProductPictureDescriptionDto;
import com.ymatou.iapi.productmanager.service.GetNewProductDescriptionInfoCall;
import com.ymatou.iapi.productmanager.service.ModifyProductDescriptionCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.utils.EnvSetup;
/**
*保存修改商品文描
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ModifyProductDescription{
	private static ModifyProductDescriptionBean modifyproductdescriptionBean = new ModifyProductDescriptionBean();
	private static ModifyProductDescriptionCall modifyproductdescriptionCall = new ModifyProductDescriptionCall();
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("保存修改商品文描");
	}

	@Before
	public void caseUp() {
		modifyproductdescriptionBean=new ModifyProductDescriptionBean();
		modifyproductdescriptionCall=new ModifyProductDescriptionCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(modifyproductdescriptionCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyProductDescription_001() {
		Logger.start(true,"保存修改商品文描");
		try {
			AddSellerProductRequest addreq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addreq);
			ProductDescriptionInfoDto productDescriptionInfoDto = new ProductDescriptionInfoDto();
			productDescriptionInfoDto.setWordContent("Super man");
			List<ProductPictureDescriptionDto> Pictures = new ArrayList<ProductPictureDescriptionDto>();
			ProductPictureDescriptionDto productPictureDescriptionDto1 = new ProductPictureDescriptionDto();
			ProductPictureDescriptionDto productPictureDescriptionDto2 = new ProductPictureDescriptionDto();
			productPictureDescriptionDto1.setPictureUrl("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71b.png");
			productPictureDescriptionDto2.setPictureUrl("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			Pictures.add(productPictureDescriptionDto1);
			Pictures.add(productPictureDescriptionDto2);
			productDescriptionInfoDto.setPictures(Pictures);
			
			modifyproductdescriptionBean.setDescriptionInfo(productDescriptionInfoDto);
			modifyproductdescriptionBean.setUserId(sellerId);
			modifyproductdescriptionBean.setProductId(productId);
			modifyproductdescriptionCall.setData(modifyproductdescriptionBean);	
			modifyproductdescriptionCall.callService();			
			
			Logger.verifyEquals("200", modifyproductdescriptionCall.getString("Code"), "验证Code");
			JSONObject productDescriptionInfo = ProductManagerCallServiceV2.getNewProductDescriptionInfo(sellerId, productId);
			Logger.verifyEquals(productDescriptionInfoDto.getWordContent(), productDescriptionInfo.get("WordContent"), "验证商品的文描文本内容");
			for(int i = 0;i<Pictures.size();i++){
				Logger.verifyEquals(Pictures.get(i).getPictureUrl(), new JSONObject(new JSONArray(productDescriptionInfo.getString("Pictures")).get(i).toString()).get("PictureUrl"), "验证PictureUrl");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyProductDescription_002() {
		Logger.start(true,"保存修改商品文描,不传买手Id");
		try {
			AddSellerProductRequest addreq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addreq);
			ProductDescriptionInfoDto productDescriptionInfoDto = new ProductDescriptionInfoDto();
			productDescriptionInfoDto.setWordContent("Super man");
			List<ProductPictureDescriptionDto> Pictures = new ArrayList<ProductPictureDescriptionDto>();
			ProductPictureDescriptionDto productPictureDescriptionDto1 = new ProductPictureDescriptionDto();
			ProductPictureDescriptionDto productPictureDescriptionDto2 = new ProductPictureDescriptionDto();
			productPictureDescriptionDto1.setPictureUrl("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71b.png");
			productPictureDescriptionDto2.setPictureUrl("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			Pictures.add(productPictureDescriptionDto1);
			Pictures.add(productPictureDescriptionDto2);
			productDescriptionInfoDto.setPictures(Pictures);
			
			modifyproductdescriptionBean.setDescriptionInfo(productDescriptionInfoDto);
			modifyproductdescriptionBean.setProductId(productId);
			modifyproductdescriptionCall.setData(modifyproductdescriptionBean);	
			modifyproductdescriptionCall.callService();			
			
			//买手id不能为空
			Logger.verifyEquals("400", modifyproductdescriptionCall.getString("Code"), "验证Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/*@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyProductDescription_003() {
		Logger.start(true,"保存修改商品文描,商品id不是买手创建的");
		try {
			AddSellerProductRequest addreq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addreq);
			ProductDescriptionInfoDto productDescriptionInfoDto = new ProductDescriptionInfoDto();
			productDescriptionInfoDto.setWordContent("Super man");
			List<ProductPictureDescriptionDto> Pictures = new ArrayList<ProductPictureDescriptionDto>();
			ProductPictureDescriptionDto productPictureDescriptionDto1 = new ProductPictureDescriptionDto();
			ProductPictureDescriptionDto productPictureDescriptionDto2 = new ProductPictureDescriptionDto();
			productPictureDescriptionDto1.setPictureUrl("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71b.png");
			productPictureDescriptionDto2.setPictureUrl("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			Pictures.add(productPictureDescriptionDto1);
			Pictures.add(productPictureDescriptionDto2);
			productDescriptionInfoDto.setPictures(Pictures);
			
			modifyproductdescriptionBean.setDescriptionInfo(productDescriptionInfoDto);
			modifyproductdescriptionBean.setProductId(productId);
			modifyproductdescriptionBean.setUserId(288484);
			modifyproductdescriptionCall.setData(modifyproductdescriptionBean);	
			modifyproductdescriptionCall.callService();			
			
			Logger.verifyEquals("200", modifyproductdescriptionCall.getString("Code"), "验证Code");
			JSONObject productDescriptionInfo = ProductManagerCallServiceV2.getNewProductDescriptionInfo(sellerId, productId);
			Logger.verifyEquals(productDescriptionInfoDto.getWordContent(), productDescriptionInfo.get("WordContent"), "验证商品的文描文本内容");
			for(int i = 0;i<Pictures.size();i++){
				Logger.verifyEquals(Pictures.get(i).getPictureUrl(), new JSONObject(new JSONArray(productDescriptionInfo.getString("Pictures")).get(i).toString()).get("PictureUrl"), "验证PictureUrl");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}*/
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyProductDescription_003() {
		Logger.start(true,"保存修改商品文描,不传productId");
		try {
			AddSellerProductRequest addreq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addreq);
			ProductDescriptionInfoDto productDescriptionInfoDto = new ProductDescriptionInfoDto();
			productDescriptionInfoDto.setWordContent("Super man");
			List<ProductPictureDescriptionDto> Pictures = new ArrayList<ProductPictureDescriptionDto>();
			ProductPictureDescriptionDto productPictureDescriptionDto1 = new ProductPictureDescriptionDto();
			ProductPictureDescriptionDto productPictureDescriptionDto2 = new ProductPictureDescriptionDto();
			productPictureDescriptionDto1.setPictureUrl("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71b.png");
			productPictureDescriptionDto2.setPictureUrl("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			Pictures.add(productPictureDescriptionDto1);
			Pictures.add(productPictureDescriptionDto2);
			productDescriptionInfoDto.setPictures(Pictures);
			
			modifyproductdescriptionBean.setDescriptionInfo(productDescriptionInfoDto);
		//	modifyproductdescriptionBean.setProductId(productId);
			modifyproductdescriptionBean.setUserId(288484);
			modifyproductdescriptionCall.setData(modifyproductdescriptionBean);	
			modifyproductdescriptionCall.callService();			
			
			//请求参数商品编号不能为空
			Logger.verifyEquals("400", modifyproductdescriptionCall.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}